package com.wander.patterns.structure.proxy.dynamicProxy;


import lombok.Data;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @description: JDK自带的代理方式实现:
 * @author: zhuyong
 * @create: 2019-09-03 17:03
 **/
@Data
public class StarHandler implements InvocationHandler {
    //交由动态代理的对象
    private RealStar realStar;

    public StarHandler(RealStar realStar) {
        this.realStar = realStar;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("统一的流程控制!");
        Object object = null;
        if(method.getName().equals("sing")){//调用真实对象的方法
            System.out.println("经纪人和明星进行交割...,准备让明星出场");
           object = method.invoke(realStar,args);
        }
        return object;
    }
}
